package hot100.logos71To80;

/**
 * @author logos
 * date 2025/7/17 13:01
 * @version v1.0
 * @Package hot100.logos71To80
 */
public class logos77 {

    /**
     * 77. 买卖股票的最佳时机
     * https://leetcode.cn/problems/best-time-to-buy-and-sell-stock/description/?envType=study-plan-v2&envId=top-100-liked
     */

    class Solution {
        public int maxProfit(int[] prices) {
            int cost = Integer.MAX_VALUE;
            int ans = 0;
            for (int price : prices) {
                cost = Math.min(cost, price);
                ans = Math.max(ans, price - cost);
            }
            return ans;
        }
    }
}
